package org.flashbrighton.as3bots.bots
{
	import org.flashbrighton.as3bots.events.BotEvent;
	import org.flashbrighton.as3bots.models.BotData;
	import org.flashbrighton.as3bots.models.CollidableType;
	import org.flashbrighton.as3bots.views.ui.Message;
	

	public class JoesBotController implements IBotController
	{
		
		private var _enginePower:Number;
		private var _steeringPower:Number;		
		private var _state:String;
		private var _health:Number;
		private var _prehealth:Number;
		
		
		public function JoesBotController()
		{
			_enginePower = 1.0;
			_steeringPower = -0.5;
			_state = "good";
		}
		
		
		public function notify(event:BotEvent):void
		{
			//Message.write("pos: " + int(event.collisionPoint * 100) / 100);
			
			if (event.collisionPoint > 0.5 || event.collisionPoint < -0.5)
			{
				_state = "bad";
			}
			else
			{
				_state = "good";
			}
			
			if (event.targetType == CollidableType.WALL)
			{
				_state = "bad";
			}
			
			if (_state == "bad")
			{		
				_enginePower = -_enginePower;
				_steeringPower = Math.random();
				_state = "good";
			}
			else if (_state == "good")
			{
				_steeringPower = 0;
			}
		}
		
		
		public function update(data:BotData):void
		{												
			if (_health)
			{
				var loss:Number = _health - data.health;
				//if (loss > 0) Message.write("loss: " + int(loss * 1000) / 10 + "%");
			}
			
			_health = data.health;
		}
		
		
		public function getEnginePower():Number
		{
			return _enginePower;
		}
		
		
		public function getSteeringPower():Number
		{
			return _steeringPower;
		}
		
	}
}